package com.uff.hmstpa.model.service.impl;

import java.util.List;

import com.uff.hmstpa.model.domain.Doctor;
import com.uff.hmstpa.model.mediator.ModelMediator;
import com.uff.hmstpa.model.persistence.DoctorDAO;
import com.uff.hmstpa.model.persistence.impl.DoctorDAOImpl;
import com.uff.hmstpa.model.service.DoctorService;
import com.uff.hmstpa.util.exception.BusinessRuleException;

public class DoctorServiceImpl implements DoctorService {
    
    private ModelMediator mediator;
    private DoctorDAO doctorDAO = DoctorDAOImpl.getInstance();

    public DoctorServiceImpl() {
    }

    public List<Doctor> retrieveDoctors() {
        return doctorDAO.load();
    }

    public Doctor retrieveDoctor(String crm) throws BusinessRuleException {
    	Doctor d = doctorDAO.retrieve(crm);
    	
    	if(d == null) {
    		throw new BusinessRuleException(this, "Nenhum doutor encontado com o CRM informado.");
    	}
    	
    	return d;
    }

	public void setMediator(ModelMediator mediator) {
		this.mediator = mediator;
	}
	
	public ModelMediator getMediator() {
		return this.mediator;
	}

}
